//07:10 10:41
//时间服务器


import org.apache.mina.core.service.IoAcceptor;
import org.apache.mina.core.session.IdleStatus;
import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.filter.codec.textline.TextLineCodecFactory;
import org.apache.mina.filter.logging.LoggingFilter;
import org.apache.mina.transport.socket.nio.NioSocketAcceptor;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.charset.Charset;
// telnet 127.0.0.1 9123
public class MinaTimeServer {
    private static final int RORT = 9123;

    public static void main(String[] args) throws IOException {
//监听网络以获取连入的连接
        IoAcceptor acceptor = new NioSocketAcceptor();

        //添加过滤器
        acceptor.getFilterChain().addLast("logger",new LoggingFilter());
        acceptor.getFilterChain().addLast("codec",new ProtocolCodecFilter(
                new TextLineCodecFactory(Charset.forName("UTF-8"))));

        acceptor.setHandler( new  TimeServerHandler());

        //设置缓冲区大小
        acceptor.getSessionConfig().setReadBufferSize(2048);
        //空闲时检查的时间
        acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE,10);

        //绑定到指定的端口
        acceptor.bind(new InetSocketAddress(RORT));

    }
}
